#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
const int N = 50010, M = N * 3;
int h[N], e[M], ne[M], w[M], idx;
int dist[N];
bool st[N];
int n;
void add(int a, int b, int c)
{
    e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
}
void spfa()
{
    memset(dist, -0x3f, sizeof dist);
    dist[0] = 0;
    queue<int> q;
    q.push(0);
    while (q.size())
    {
        int t = q.front();
        q.pop();
        st[t] = false;
        for (int i = h[t]; ~i; i = ne[i])
        {
            int j = e[i];
            if (dist[j] < dist[t] + w[i])
            {
                dist[j] = dist[t] + w[i];
                if (!st[j])
                {
                    st[j] = true;
                    q.push(j);
                }
            }
        }
    }
}
int main()
{
    cin >> n;
    memset(h, -1, sizeof h);
    for (int i = 1; i < N; i++)
    {
        add(i - 1, i, 0);
        add(i, i - 1, -1);
    }
    while (n--)
    {
        int a, b, c;
        cin >> a >> b >> c;
        a++, b++;
        add(a - 1, b, c);
    }
    spfa();
    cout << dist[N - 1] << endl;
    return 0;
}